class Solution {
public:
    vector<int> occurrencesOfElement(vector<int>& nums, vector<int>& queries, int x) {
        unordered_map<int,vector<int>> has;

        vector<int> ret;

        for(int i=0;i<nums.size();i++)
        {
            has[nums[i]].push_back(i);
        }
        for(int i=0;i<queries.size();i++)
        {
            if(!has.count(x) || has[x].size()<queries[i])
            {
                ret.push_back(-1);
            }
            else {
                ret.push_back(has[x][queries[i]-1]);
            }
        }
        return ret;
    }
};
